﻿using System.Collections.Generic;
using System.Data;
using TfsReports.Web.Helpers;

namespace TfsReports.Web.Models
{
    /// <summary>
    /// Changeset
    /// </summary>
    public class Changeset : Entity
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Changeset"/> class.
        /// </summary>
        /// <param name="dataRecord">The data record.</param>
        public Changeset(IDataRecord dataRecord)
        {
            Id = dataRecord.GetInt32(dataRecord.GetOrdinal("ChangesetId"));
            Title = dataRecord.GetString(dataRecord.GetOrdinal("ChangesetTitle"));
        }

        private List<Build> _builds;
        /// <summary>
        /// Gets or sets the builds.
        /// </summary>
        /// <value>The builds.</value>
        public List<Build> Builds
        {
            get
            {
                if (_builds == null)
                    _builds = TfsWarehouse.GetBuildsForChangeset(Id);
                return _builds;
            }
        }
    }
}
